Results 1 to 5 of 5

Thread: Server Side Menu System experiment

  1. #1

    Default Server Side Menu System experiment

    Straight from Elglabs..being weeks behind on work, I decide to open mohaa for once in a while, maybe it was all the excitement over the AWESOME BENEFITS of adding SQL

    (note video still uploading , prob take a couple of hours...but time diff, youre all asleep anyway??)

    http://youtu.be/U8YmCR3WDXY

    I had an idea for a mod; a way in which it would be possible to use the new ihuddraw...combined with a globalwidget mouse,. To detect "buttons".

    Designed for maybe an accept screen, login screen or something; not much else!!
    THe mod is NO WHERE NEAR FINISHED..nore will I finish it; its concept stuff from the ElgLab

    Its as follows..you create a "menu"..the menu holds all its "children"..which you can, hide show...create strings, boxes or buttons within that "menu"..You assign a player and display it for the player...he can only have 1 menu on at a time at the moment .

    The button is created with a feedback thread, the thread is executed uppon click..tada.

    It needs someone MUCH better at maths than me..not difficult..I simply cant sit and play, tho I would love to. It needs properly detecting the fake mouse movement..all I have is simple movement.

    The whole script is this:
    Code:
    main:
    
    	
    //make a new menu	
    local.newMenu = self waitexec global/ihud.scr::createMenu
    //must set the player 
    local.newMenu waitexec global/ihud.scr::setPlayer self
    
    //
    // this is now our menu object
    // local.newMenu 
    //
    
    //make a button on this menu
    local.newMenu waitexec global/ihud.scr::drawButton 220 190 101 51 "Press Me" global/elghud.scr::clicked_button
     
    //note bug its already alpha 1, need to set it on off with use menu etc...but this is a test demo
    ///display his view menu
    self exec global/ihud.scr::useMenu local.newMenu 
    
    
    end
    
    clicked_button:
    	iprintlnbold "CLICKED FEEDBACK IN SCRIPT"
    end
    it uses a custom STATE,,,which would probably be forced...but I'm just going into it with state too..

    The state executes the above and freezes the player (the way a freeze is properly done )

    The camera is allowed to move but hidden by a spawned one. (needs a tweak)

    oh and here is a video;

    its an ugly button; but meh...You could use mohaa "apply" etc..



    main script:

    Code:
    //should auto run if this is called
    init:
    	//don't run twice
    	if(level.doneHudInit == 1)
    	{
    		end
    	}
    
    	//tell the game we already did init for huds
    	level.doneHudInit = 1
    
    //THIS WOULD BE BETTER TO MAKE A GLOBAL FIND FREE ID METHOD; prob in framework, not bothering now for an experiment
    	//the index on which to start hud draws
    	level.startHudIndex = 112
    
    	level.canvID = 1
    
    end
    
    //make a enw menu
    createMenu:
    
    	if(level.doneHudInit != 1)
    	{
    		waitthread init
    	}
    
    	local.canvas = local CreateListener
    	local.canvas targetname  ("canv" + level.canvID )
    	level.canvID++
    	
    	//the player to draw this to
    	if(self.classname == "Player")
    	{
    		local.canvas.player = self
    	}
    
    	//array of all hud we contain..so we can hide if needed
    	local.canvas.hudArray[0] = -1
    	
    	//our buttons
    	local.canvas.buttonArray[0] = -1
    
    end local.canvas
    
    
    //set the player to use
    setPlayer local.player:
    	self.player = local.player
    end
    
    
    //incrament global id
    getNewID local.menuID:
    	
    	//add to our global id 
    	level.startHudIndex++
    	
    	thread listenerAddHUD level.startHudIndex
    
    end level.startHudIndex
    
    listenerAddHUD local.hudID:
    
    	//add this hud to our hud list
    
    	local.id = self.hudArray.size 
    	if(self.hudArray[0] == -1)
    	{
    		local.id = 0
    	}
    	
    	self.hudArray[local.id] = local.hudID
    
    end
    
    ////////////////////////////
    // creation
    ////////////////////////////
    //draw a box
    //returns index of this hud
    drawBox local.x local.y local.w local.h:
    
    	//the index to use for the rect
    	local.index = waitthread getNewID
    	
    	thread setColour local.index 1 1 1
    	thread setAlpha local.index 0.0
    	thread setAlign local.index "left" "top"
    	thread setVirtualsize local.index 1
    	thread setRect local.index local.x local.y local.w local.h
    	thread setShader local.index "textures/mohmenu/black.tga"
    
    //	thread setShader local.index "textures/mohmenu/black.tga"
    
    end local.index
    
    ////////////////////////////
    //draw a string
    //returns index of this hud
    drawString local.x local.y local.w local.h local.string:
    
    	//the index to use for the rect
    	local.index = waitthread getNewID
    	
    	thread setColour local.index 1 1 1 
    	thread setAlpha local.index 0.0
    	thread setAlign local.index "left" "top"
    	thread setVirtualsize local.index 1
    	thread setRect local.index local.x local.y local.w local.h
    	thread setString local.index local.string
    
    end local.index
    
    //draws a button
    //returns index of this hud
    drawButton local.x local.y local.w local.h local.string local.function:
    
    	local.button = local CreateListener 
    	local.id = 1 //cba to do this
    	local.button targetname ("btn" + local.id )
    	
    	//callback
    	local.button.function = local.function
    	 
    	//set button player
    	local.button waitthread setPlayer self.player
    
    	local.width = 10
    	local.bgButtonID = waitthread drawBox local.x local.y local.w local.h 
    	local.fgButtonID = waitthread drawBox ( local.x + ( local.width / 2 )  ) ( local.y + ( local.width / 2 ) )  ( local.w - local.width ) ( local.h - local.width )
    	thread setShader local.fgButtonID "textures/mohmenu/loadingbar"
    	local.captionID = self waitthread drawString ( local.x + ( local.width  )  ) ( local.y + ( local.width  ) )  ( local.w - ( local.width * 2 ) ) ( local.h - ( local.width * 2 ) ) local.string
    	
    	//add hud ids to our menu
    	thread listenerAddHUD local.bgButtonID
    	thread listenerAddHUD local.fgButtonID
    	thread listenerAddHUD local.captionID
    	
    	//add hud ids to our menu
    	local.button.bgButtonID = local.bgButtonID
    	local.button.fgButtonID = local.fgButtonID
    	local.button.captionID = local.captionID
    	
    	//dimensions
    	local.button.x = local.x
    	local.button.endx = ( local.x + local.w )
    	local.button.y = local.y
    	local.button.endy = ( local.y + local.w )
    	
    	//save our button 
    	local.buttons = self.buttonArray.size
    	if(self.buttonArray[0] == -1)
    	{
    		local.buttons = 0
    	}
    
    	self.buttonArray[local.buttons] = local.button
    
    end  local.button
    
    ////////////////////////////
    // properties
    ////////////////////////////
    
    
    //sets string
    setString local.index local.string:
    	ihuddraw_string self.player local.index local.string
    end local.index
    
    //sets shader
    setShader local.index local.shader:
    	ihuddraw_shader self.player local.index local.shader
    end local.index
    
    //sets rect
    setRect local.index local.x local.y local.w local.h:
    	ihuddraw_rect self.player local.index local.x local.y local.w local.h
    end local.index
    
    //sets font
    setFont local.index local.font:
    	ihuddraw_font self.player local.index local.font
    end local.index
    
    //sets virtual size
    setVirtualsize local.index local.res:
    	ihuddraw_virtualsize self.player local.index local.res
    end local.index
    
    //sets alpha
    setAlpha local.index local.alpha:
    	ihuddraw_alpha self.player local.index local.alpha
    end local.index
    
    //sets alignment
    setAlign local.index local.h local.v:
    	ihuddraw_align self.player local.index local.h local.v
    end local.index
    
    //sets colour
    setColour local.index local.r local.g local.b:
    	ihuddraw_color self.player local.index  local.r local.g local.b
    end local.index
    
    
    ////////////////////////////
    // use the menu
    ////////////////////////////
    useMenu local.menuID:
    
    	if(self.isUsingMenu)
    	{
    		end
    	}
    	
    	//set the player to display for
    	local.menuID thread setPlayer self
    
    	self.isUsingMenu = 1
    
    //bug will be we can only have 1 menu at a time atm
    	self.activeMenu = local.menuID
    
    	//mouse is in middle
    	self.mousePositionX = 320
    	self.mousePositionY = 240
    
    	self thread createUseCamera
    	self thread displayMouse
    	
    	//loop througha dn display all the menus in 
    	for(local.i=0;local.i<=self.activeMenu.hudArray.size - 1;local.i++)
    	{
    		ihuddraw_alpha self self.activeMenu.hudArray[local.i] 1.0
    	}
    end
    
    
    trackMouse:
    		
    	local.position = waitthread getViewPosition
    	local.team = self.dmteam
    
    	while(isalive self && self.dmteam == local.team && self.isUsingMenu)
    	{
    		waitframe
    		local.newPosition = waitthread getViewPosition
    	
    	//	iprintln ("OLD ANGLES  " +  local.position  )
    	//	iprintln ("NEW ANGLES  " +  local.newPosition  )
    
    		if( local.newPosition[2] > local.position[2] )
    		{
    			self.mousePositionY -= 20
    		}
    
    		if(local.newPosition[2] < local.position[2])
    		{
    			self.mousePositionY += 20
    		}
    
    		if( local.newPosition[1] > local.position[1] )
    		{
    		//	self.mousePositionX -= 20
    		}
    
    		if(local.newPosition[1] < local.position[1])
    		{
    		//	self.mousePositionX -= 20
    		}
    
    		self waitthread moveMouse self.mousePositionX self.mousePositionY
    
    		local.position = local.newPosition
    		
    		//did we hit a btn
    		local.didHit = waitthread didHitButton 
    		if(local.didHit != -1)
    		{
    			local.didHit thread highlightButton 
    
    			//pressed
    			if(self.fireheld)
    			{
    				local.didHit thread checkClick
    			}
    		}
    	}
    
    end
    
    getViewPosition:
    
    	local.position = self.hudCam.origin
    	local.position += angles_toforward(self.viewangles ) * 100
    
    end local.position
    
    didHitButton:
    
    	for(local.o =0 ; local.o <= self.activeMenu.buttonArray.size - 1; local.o++)
    	{
    
    		local.x = self.mousePositionX
    		local.y = self.mousePositionY
    
    		local.button = self.activeMenu.buttonArray[local.o]
    //iprintlnbold local.button.x
    		if( ( local.x > local.button.x && local.x < local.button.endx ) && ( local.y > local.button.y && local.y < local.button.endy ) )
    		{
    		//	iprintlnbold "HIT THE BUTTON"
    			end local.button
    		}
    
    	}
    
    end -1
    	
    checkClick:
    	if(self.function == "Const Arrray")
    	{
    		exec self.function[0]::self.function[1]
    	}
    	else
    	{
    		exec self.function
    	}
    end
    
    highlightButton:
    	self thread setColour self.captionID 1 0 0
    	self thread setShader self.fgButtonID "textures/mohmenu/rangers"
    	waitframe
    	self thread setColour self.captionID 1 1 1
    	self thread setShader self.fgButtonID "textures/mohmenu/loadingbar"
    end
    
    displayMouse:
    
    	self thread trackMouse
    
        self stufftext "globalwidgetcommand dday1 shader townhallwindow"
        self stufftext "globalwidgetcommand dday1 fgcolor 0 0 0 0"
        self stufftext "globalwidgetcommand dday1 bgcolor 0 0 0 0"
        self stufftext "globalwidgetcommand dday1 fadein 0"
        self stufftext "globalwidgetcommand dday1 menu dday1 640 480 NONE 0"
        self stufftext "globalwidgetcommand dday1 virtualres 1" 
        self stufftext "globalwidgetcommand dday1 fullscreen 1" 
    
        self stufftext "globalwidgetcommand june6 align left top" 
        self stufftext "globalwidgetcommand june6 fullscreen 1" 
        self stufftext "globalwidgetcommand june6 virtualres 1" 
        self stufftext "globalwidgetcommand june6 borderstyle NONE"
        self stufftext "globalwidgetcommand june6 shader mouse" // textures/hud/healthback"
        self stufftext "globalwidgetcommand june6 rect 320 240 50 50"
        self stufftext "globalwidgetcommand june6 fgcolor 5.50 5.50 5.50 5.50"
        self stufftext "globalwidgetcommand june6 bgcolor 0 0 0 0"
    
        self stufftext "showmenu dday1"
    
    end
    
    
    moveMouse local.x local.y:
    
        self stufftext ("globalwidgetcommand june6 rect " + local.x + " " + local.y + " 50 50" )
    
    end
    
    
    createUseCamera:
    	
    	//make a camera to hinder the players view
    	local.camera = spawn Camera
    	
    	local.camera = spawn Camera
    
    	local.camera targetname ("cam" + self.entnum)
    	local.camerause = spawn trigger_camerause target ("cam" + self.entnum)
    	local.camerause doUse self
    	local.camera notsolid
    
    	//users view cam
    	self.hudCam = local.camera
     	
    	local.camera.origin = self gettagposition "eyes bone"
    	local.camera.origin += self.forwardvector * 20
    	local.camera.angles = angles_toforward self.viewangles
    end

    STATE

    Code:
    state ELGSTATE
    {
    
    	movetype climbwall
    	camera behind
    
    	entrycommands
    	{
    		exec global/elghud.scr
    		viewmodelanim idle
    		deactivateweapon righthand
    	}
    	
    	action
    	{
    		idle : default // no torso animation
    	}
    
    	states
    	{
    		STAND		: +JUMP
    	}
    }
    because I see a drastic lack of use of them...ill explain

    the climbwall movetype stops any input from the engine, as it would use animations.

    the camera is as normal.

    the idle animation players by default...so you can see the player is in a menu..he stands still.

    to get out of it for debug ..I use +jump...could simply use "resetstate" etcServSide Menu System concept.rar

  2. #2
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,245

    Default

    Sor is implementing similar system in the framework It's a very good concept

  3. #3
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Great minds think alike I'm not the best at math but I have tried to convert a player's viewangles to a 2D screen position before.
    It seemed quite accurate for 1920x1080 except for the fact that the coords were backwards in my output (negative where it should be positive and vice versa).

    Though with your method, I think your trackMouse thread just needs some tweaking . Like, why the number 20?
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  4. #4

    Default

    not sure why res is coming into play.... everything is 320x240 because of virtual size.

    20 is the "speed" at which the mouse moves, its a fake mouse. it was just a quick play, I couldnt spend more than 2 hours on the whole thing, so I think I did quite a lot in those 2 hours.

    FOr the tweaking, it was just a quick play, if I was more serious I would be taking north facing vectors of the map into account and working out where abouts the origin is compared to the last one....then if its left...ive moved the mouse left...quite simple...not need to convert the object to screenspace.

    and I would say any system which uses reborn should be done almost with the client patch too too.


    I knew there was going to be a ihud system , but didnt know you were going to implement click detection. pretty cool...well here is a concept anyway,
    Last edited by Elgan; May 1st, 2013 at 08:35 AM.

  5. #5
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,071

    Default

    Is this a serverside or clientside mod or would it require both? As far as I know, menus are rendered clientside correct?

    EDIT: I answered my own question. Sorry didn't read the title. Wow, rendering menu's serverside. That's pretty cool man!

    A while ago, I was interested in writing a menu for MOHAA too. Only thing is my scripting is horrible so I did it within the wrapper. Obviously the concepts will be different because I'm using engine functionality as opposed to the built in scripting, but here is what I did.

    Here is an image: http://www.x-null.net/James/version/menu.JPG

    Full tutorial\explanation written on TMT a while ago here: http://www.modtheater.com/threads/tu...9/#post-312360

    Maybe it will help you guys out some? Nice job though!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •